import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { GlobalState } from "@/store/interface";
import { useCreateActionFunction } from "@/store/hooks";

const InitialState: GlobalState = {
	token: "",
};

const globalSlice = createSlice({
	name: "global",
	initialState: InitialState,
	reducers: {
		setToken(state: GlobalState, { payload }: PayloadAction<string>) {
			state.token = payload;
		},
	}
});

export const useGlobalActionFunction = useCreateActionFunction(globalSlice);

export default globalSlice.reducer;
export const { setToken } = globalSlice.actions;
